package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.mapper.DepartmentMapper;
import cn.wolfcode.rbac.pojo.Department;
import cn.wolfcode.rbac.pojo.Employee;
import cn.wolfcode.rbac.service.DepartmentService;
import cn.wolfcode.rbac.util.PageResult;
import cn.wolfcode.rbac.util.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void insertpojo(Department department) {
        departmentMapper.insertpojo(department);
    }

    @Override
    public List<Department> selectall() {

        List<Department> selectall = departmentMapper.selectall();
        return selectall;
    }

    @Override
    public void save(Department department) {
        if (department.getId() != null) {
            departmentMapper.updatebyid(department);
        } else {
            departmentMapper.save(department);
        }
    }

    @Override
    public Department selectbyid(Integer id) {

        return departmentMapper.selectbyid(id);
    }

    @Override
    public void delect(Integer id) {
        departmentMapper.delect(id);
    }

    @Override
    public PageResult PageResult(QueryObject queryObject) {
        int countdep = departmentMapper.countdep();
        if (countdep != 0) {
            List<Department> pageresult = departmentMapper.pageresult(queryObject);
            return new PageResult(pageresult, countdep, queryObject.getCurrentPage(), queryObject.getPageSize());
        } else {
            return new PageResult(queryObject.getCurrentPage(), queryObject.getPageSize());
        }


    }

    @Override
    public PageInfo<Department> getallemp(QueryObject queryObject) {
        PageHelper.startPage(queryObject.getCurrentPage(), queryObject.getPageSize());
        List<Department> selectall = departmentMapper.selectall();
        return new PageInfo<>(selectall);
    }


}
